<template>
    <div class="dormitory-front">
        <vHead appPath="/dormitory" appTitle="宿舍管理">
            <el-button type="primary" v-if="managerole" @click="goManage">宿舍管理</el-button>
        </vHead>
        <main class="main">
            <router-view />
        </main>
        <foote />
    </div>
</template>
<script>
import vHead from "@/components/common/header";
import vFoot from '@/components/common/footer';

export default {
    components: {
        vHead,
        vFoot
    },
    data() {
        return {
            managerole: false,
        }
    },
    created() {
        this.checkLogin();
    },
    methods: {
        goManage() {
            let url = sessionStorage.getItem('manage_url');
            let host = sessionStorage.getItem('host');
            let token = sessionStorage.getItem('redirect_params');

            window.open(decodeURIComponent(url + '/admin' + token + '&host=' + host + '&routerUrl=' + '/life/dormitory/accommodation-registration')); 
        },
        checkLogin() {
            let success = res => {
                if (!is_empty(res.data)) {
                    this.managerole = true;
                } else {
                    this.managerole = false;
                }
            };
            let fail = (res => {})

            this.$ajax({
                url: "api/dormitory/checkDormitoryRoleByUser",
                method: "get",
                params: {user_id: this.$g.user_id},
                func: {
                    success: success,
                    fail: fail
                }
            });
        }
    },
};
</script>     

